package org.smartboot.fanyun;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.util.Iterator;
import java.util.List;

public class HIKEventBodyDecode {
    public static void bodyDecoder(InputStream body){
        SAXReader reader = new SAXReader();
        try {
            // 通过reader对象的read方法加载数据,获取docuemnt对象。
            Document document = reader.read(body);
            // 通过document对象获取根节点bookstore
            Element eventStore = document.getRootElement();
            // 通过element对象的elementIterator方法获取迭代器
            Iterator it = eventStore.elementIterator();
            // 遍历迭代器，获取根节点中的信息
            while (it.hasNext()) {
                Element event = (Element) it.next();
                if(!"PeopleCounting".equals(event.getName())){
                    System.out.println("节点名：" + event.getName() + "--节点值：" + event.getStringValue());
                }else{
                    System.out.println("节点名：" + event.getName() + "--节点值：");
                    Iterator itt = event.elementIterator();
                    while (itt.hasNext()) {
                        Element child = (Element) itt.next();
                        if(!"TimeRange".equals(child.getName())){
                            System.out.println("子节点名：" + child.getName() + "--子节点值：" + child.getStringValue());
                        }else{
                            System.out.println("子节点名：" + child.getName() + "--子节点值：" );
                            Iterator ittt = child.elementIterator();
                            while (ittt.hasNext()) {
                                Element childc = (Element) ittt.next();
                                System.out.println("三级子节点名：" + childc.getName() + "--三级子节点值：" + childc.getStringValue());
                            }
                        }


                    }
                }




            }
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
